<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <textarea name="" id="" cols="30" rows="10"></textarea>
  <button>发表</button>
  <ul>

  </ul>

  <script>
    var content = document.querySelector('textarea')
    var button = document.querySelector('button')
    var ul = document.querySelector('ul')

    button.onclick = function() {
      var value = content.value.trim()  // 去除字符串前后空白

      if(value.length === 0) {
        return alert('请输入内容')
      }

      var li = document.createElement('li')
      li.innerHTML = value + '<a href="javascript:;">删除 </a>'

      ul.appendChild(li)  // 从后边插入
      // ul.insertBefore(li, ul.children[0])  // 从前边插入
      content.value = ''

      var alist = document.querySelectorAll('a')

      for(var i = 0; i < alist.length; i++) {
        alist[i].onclick = function() {
          ul.removeChild( this.parentNode )
        }
      }

    }



  </script>
</body>
</html>